<?php
	class AdminUtility{
		public function inquire_catch($params){
			/*$params['view'] = $this->getPost("view");
			$params['collector'] = $this->getPost("collector");
			$params['specie'] = $this->getPost("specie");
			$params['site']=$this->getPost("site");
			$params['period'] = $this->getPost("period");
			$params['f_date'] = $this->getPost("f_date");
			$params['t_date'] = $this->getPost("t_date");*/
			
			Zend_loader::loadClass("Receipt");
			Zend_loader::loadClass("Organism");
			Zend_loader::loadClass("Organization");
			Zend_loader::loadClass("FishingArea");
			Zend_loader::loadClass("Fisher");
			
			$query = new QueryCreator();
			$query->addSelect(" r.date_updated,r.supplier_fishing_area_id,r.supplier_org_id,r.org_organism_id,
							f.last_name,f.first_name,fa.fishing_area_name,o.name,oz.name as organism_name,
							r.doa_quantity,r.reject_quantity,r.received_quantity");
			$query->addFrom( Receipt::_tablename ." as  r ");
			$query->addJoin(" LEFT JOIN ". Organism::_tablename . " as oz on r.org_organism_id=oz.organism_id ");
			$query->addJoin(" LEFT JOIN ". Organization::_tablename . " as o on r.supplier_org_id=o.org_id ");
			$query->addJoin(" LEFT JOIN ". FishingArea::_tablename . " as fa on fa.fishing_area_id=r.supplier_fishing_area_id ");
			$query->addJoin(" LEFT JOIN ". Fisher::_tablename . " as f on fa.fishing_area_id=f.fishing_area_id ");
			
			//output date,area,collector,specie,quantity
			switch($params['view']){
				case "collector":
					
					Zend_loader::loadClass("Fishers");
					$fishers=new Fishers();
					$fishers->loadWhere("fisher_id=".$params['collector']);
					$fisher=$fishers->toArray();
					
					$query->addWhere(" f.fisher_id=".$fisher[0]['fisher_id']." ");
					
					/*select r.date_updated,r.supplier_fishing_area_id,r.supplier_org_id,r.org_id,
						r.doa_quantity,r.reject_quantity,r.received_quantity,
						f.last_name,f.first_name,fa.fishing_area_name,o.name,oz.name as organism_name 
					from projecte_sales.receipts as r
					left join projecte_inventory.organisms as oz
					on r.org_id=oz.organism_id
					left join projecte_entity.organizations as o
					on r.supplier_org_id=o.org_id
					left join projecte_entity.fishing_areas as fa 
					on fa.fishing_area_id=r.supplier_fishing_area_id
					left join projecte_entity.fishers as f
					on fa.fishing_area_id=f.fishing_area_id
					where f.fisher_id=%d and r.data_created<%d and r.data_updated>%d*/
				break;
				case "specie":
					
					Zend_loader::loadClass("Organisms");
					$orgs=new Organisms();
					$orgs->loadWhere("organism_id=".$params['specie']);
					$org=$orgs->toArray();
					
					$query->addWhere(" oz.organism_id=".$org[0]['organism_id']." ");
					
					/*select r.date_updated,r.supplier_fishing_area_id,r.supplier_org_id,r.org_id,
						r.doa_quantity,r.reject_quantity,r.received_quantity,
						f.last_name,f.first_name,fa.fishing_area_name,o.name,oz.name as organism_name 
					from projecte_sales.receipts as r
					left join projecte_inventory.organisms as oz
					on r.org_id=oz.organism_id
					left join projecte_entity.organizations as o
					on r.supplier_org_id=o.org_id
					left join projecte_entity.fishing_areas as fa 
					on fa.fishing_area_id=r.supplier_fishing_area_id
					left join projecte_entity.fishers as f
					on fa.fishing_area_id=f.fishing_area_id
					where r.org_id=1 and r.date_created<1 and r.date_updated>2*/
				break;
				case "site":
					
					Zend_loader::loadClass("FishingAreas");
					$fas=new FishingAreas();
					$fas->loadWhere("fishing_area_id=".$params['site']);
					$fa=$fas->toArray();

					$query->addWhere(" fa.fishing_area_id=".$fa[0]['fishing_area_id']." ");
					
					/*select r.date_updated,r.supplier_fishing_area_id,r.supplier_org_id,r.org_id,
						r.doa_quantity,r.reject_quantity,r.received_quantity,
						f.last_name,f.first_name,fa.fishing_area_name,o.name,oz.name as organism_name 
					from projecte_sales.receipts as r
					left join projecte_inventory.organisms as oz
					on r.org_id=oz.organism_id
					left join projecte_entity.organizations as o
					on r.supplier_org_id=o.org_id
					left join projecte_entity.fishing_areas as fa 
					on fa.fishing_area_id=r.supplier_fishing_area_id
					left join projecte_entity.fishers as f
					on fa.fishing_area_id=f.fishing_area_id
					where fa.fishing_area_id=1 and r.date_created<1 and r.date_updated>2*/
					
				break;
			}
			
			if(!empty($params['f_date'])) 
				$query->addWhere(" r.date_created > '". $params['f_date'] . "'" );
			if(!empty($params['t_date'])) 
				$query->addWhere(" r.date_updated < '". $params['t_date'] . "'" );
			
			$db = DBCon::instance();
			//echo $query->createSQL();
			$result = $db->executeQuery($query->createSQL());
			
			return $result;
		}
		
		public function inquire_ors($params){
			/*$params['entity_type'] 	= $this->getPost("entity_type");
			$params['entity'] 		= $this->getPost("entity");
			$params['batch'] 		= $this->getPost("batch");
			$params['tank'] 		= $this->getPost("tank");
			$params['specie'] 		= $this->getPost("specie");*/
			
			//tank moid common_name size gender age quantity daa reason 
			//date_of_last_daa batch_no. MAC_certified
			
			/*
			 age daa date_of_last_daa MAC_certified
			 */
		}
	
		
	}
?>